package barrel_kong;

import java.awt.Graphics;
import java.util.LinkedList;

import javax.swing.JFrame;

import kong_gui_items.BaseGraphics;
import kong_gui_items.GraphicsPainters;

/**
 * This is the view
 *
 */
public class GameGui extends JFrame{

	private static final long serialVersionUID = 1733676334321587732L;

	//BufferStrategy strategy;
	GraphicsPainters mainComonent;
	GameState model;
	LinkedList<BaseGraphics> list;
	
	public GraphicsPainters getMainComonent() {
		return mainComonent;
	}

	public GameGui(GameState m)
	{
		model = m;
		list = m.getLevelItems();
		
		mainComonent = new GraphicsPainters(list);
		this.setSize(m.getWindowWidth() + 15, m.getWindowHeight()+37);
		this.setVisible(true);
		this.setResizable(true);
		this.setLocationRelativeTo(null);	//Center window on screen
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		//Add components to the frame
		add(mainComonent);
		mainComonent.requestFocusInWindow();
	}

	
	public void refreshComponentsFromModel()
	{
		mainComonent.setItemsToPaint(model.getLevelItems());
		mainComonent.requestFocusInWindow();
		
	}
	
	@Override
	public void paintComponents(Graphics g) {
		super.paintComponents(g);
		mainComonent.paint(g);
	}
}
